import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

Dio dio = Dio();

class Detail extends StatefulWidget {
  var arguments;
  Detail({Key key, this.arguments}) : super(key: key);

  @override
  _DetailState createState() => _DetailState();
}

class _DetailState extends State<Detail> {
  var listId;
  @override
  void initState() {
    super.initState();
    this.getIdlist();
  }

  Widget build(BuildContext context) {
    print(this.listId is Map);
    return Scaffold(
        appBar: AppBar(
          title: Text('电影'),
          centerTitle: true,
          elevation:0,
        ),
        body: this.listId is Map
            ? Container(
                decoration: new BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight,
                    colors: [Colors.lime[800], Colors.orangeAccent[200]],
                  ),
                ),
                padding: EdgeInsets.only(top:10,bottom: 0,left: 10,right: 10),
                child: ListView(
                  children: <Widget>[
                    Container(
                      height: 180,
                      child: Row(
                        children: <Widget>[
                          Image.network(
                            this.listId['images']['small'],
                            fit: BoxFit.cover,
                          ),
                          Container(
                            width: 210,
                              padding: EdgeInsets.only(left: 20),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Container(
                                    width: 250,
                                    child: Text(
                                      this.listId['title'],
                                      overflow: TextOverflow.ellipsis,
                                      style: TextStyle(
                                          fontSize: 25, color: Colors.white),
                                    ),
                                    
                                  ),
                                  
                                  SizedBox(
                                    height: 10,
                                  ),
                                  Text(
                                      '电影类型  : ${this.listId['genres'].join(' ')}',
                                      style: TextStyle(color: Colors.white54)),
                                  SizedBox(
                                    height: 5,
                                  ),
                                  Container(
                                      margin:
                                          EdgeInsets.only(top: 10),
                                      width: 200,
                                      child: Text(
                                        '上映时间 : ${this.listId['pubdates'].join('   ')}',
                                        style: TextStyle(color: Colors.white54),
                                        softWrap: true,
                                      )),
                                      SizedBox(
                                        height: 5,
                                      ),
                                  Text('片长：' + this.listId['durations'][0],
                                      style: TextStyle(color: Colors.white54)),
                                      
                                      new FlatButton(
    child: new Text('预告'),
    onPressed: () {
      Navigator.pushNamed(context, '/video',arguments: {"url": this.listId['trailer_urls'][0]});
      // print(this.listId['trailer_urls'][0]) ;
    },
    textColor:Colors.white70,
    color:Colors.white24
)
                                ],
                              )),
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(top: 10, bottom: 19),
                      child: Text(
                        '简介',
                        style: TextStyle(color: Colors.white, fontSize: 23),
                      ),
                    ),
                    Container(
                      child: Text(this.listId['summary'],
                          style: TextStyle(color: Colors.white, fontSize: 15),
                          overflow: TextOverflow.ellipsis,
                          maxLines: 6),
                    ),
                    SizedBox(height: 20,),
                    Text('评论',style: TextStyle(color: Colors.white, fontSize: 20)),
                    SizedBox(height:10),
                    ...this.getContaer()
                 
                  ],
                ))
            : Text('加载中'));
  }

  getIdlist() async {
    var requests = await dio.get(
        'https://douban.uieee.com/v2/movie/subject/${widget.arguments['id']}');
    print(
        'https://douban.uieee.com/v2/movie/subject/${widget.arguments['id']}');
    this.setState(() {
      listId = requests.data;
    });
  }

  getlist() {
    var list = this.listId['genres'].map((item) {
      return item;
    });
    return list;
  }

  getContaer() {
    var getlist = this.listId['popular_reviews'].map((item) {
      return Container(
        color: Colors.white70,
        child: Column(
          children: <Widget>[
            SizedBox(height:10),
            ListTile(
              leading: Container(
                  width: 30,
                  height: 30,
                  decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      image: DecorationImage(
                          image: NetworkImage(item['author']['avatar']),
                          fit: BoxFit.cover))),
              title: Text(
                item['author']['name'],
                style: TextStyle(fontSize: 16.0),
              ),
              subtitle: Text(item['title']),
            ),
            Padding(
              padding: EdgeInsets.fromLTRB(20, 0, 20, 30),
              child: Text(item['summary']),
            )
          ],
        ),
      );
    });
    return getlist;
  }


}
